package cn.ivicar.iov.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @program: iov
 * @description: ${description}
 * @author: Mr.Wang
 * @create: 2018-08-16 20:21
 **/
public class DateUtil {

    /**
     * 通过该方法获得套餐开始时间
     *
     * @return start_time
     */
    public Date getStartTime() {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int i = 0;
        if((i =calendar.get(Calendar.MONTH))== 12){
            calendar.set(Calendar.YEAR,calendar.get(Calendar.YEAR)+1);
            calendar.set(Calendar.MONTH,1);
        }
        else{
            calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH)+1);
        }
        calendar.set(Calendar.DATE,1);
        calendar.set(Calendar.HOUR_OF_DAY,0);
        calendar.set(Calendar.MINUTE,0);
        calendar.set(Calendar.SECOND,0);
        date = calendar.getTime();
        return date;
    }
    /**
     *通过该方法获得套餐结束时间
     *
     * @return end_time
     */
    public Date getEndTime(String duration) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int i = 0,Duration=0;
        try {
            Duration = Integer.parseInt(duration);
        }catch (NumberFormatException e){
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        if((i =calendar.get(Calendar.MONTH)+Duration)>12){
            calendar.set(Calendar.YEAR,calendar.get(Calendar.YEAR)+1);
            calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH)+Duration-12);
        }
        calendar.set(Calendar.YEAR,calendar.get(Calendar.YEAR));
        calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH));
        calendar.set(Calendar.DATE,1);
        calendar.roll(Calendar.DATE,-1);
        calendar.set(Calendar.HOUR_OF_DAY,23);
        calendar.set(Calendar.MINUTE,59);
        calendar.set(Calendar.SECOND,58);
        date = calendar.getTime();
        return date;
    }
    /**
     *通过该方法获取体验期结束时间
     *
     * @return end_time
     */
    public Date getProbationEndTime(Date date){
        int i = 0;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH)+1);
        calendar.set(Calendar.DATE,1);
        calendar.roll(Calendar.DATE,-1);
        return date;
    }
    
}
